import sun.reflect.generics.tree.Tree;

public class LC0700 {
    public static void main(String[] args) {
        TreeNode node = new TreeNode();
        node.val = 4;
        node.left = new TreeNode(2, new TreeNode(1), new TreeNode(3));
        node.right = new TreeNode(7);
        System.out.println(searchBST(node, 2));
    }

    public static TreeNode searchBST(TreeNode root, int val) {
        if (root == null || root.val == val) {
            return root;
        } else if (root.val < val) {
            return searchBST(root.right, val);
        } else {
            return searchBST(root.left, val);
        }
    }
}


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
